const readline = require('readline-sync');
// 电脑点数：10～21
// 玩家点数：1～10，玩家总点数大于21，就爆了
// 比较总点数，谁大谁赢

let player_win = 0, computer_win = 0;
//比较函数 记录比分
function judge(a, b) {
    if (b == -1) {
        computer_win++;
        console.log(`你爆了，游戏结束,比分：${player_win}:${computer_win}`);
    } else if (a > b) {
        player_win++;
        console.log(`玩家赢，电脑点数是${b},比分：${player_win}:${computer_win}`);
    } else if (a == b) {
        console.log(`平局，电脑点数是${b},比分：${player_win}:${computer_win}`);
    } else {
        computer_win++;
        console.log(`电脑赢，电脑点数是${b},比分：${player_win}:${computer_win}`);
    }

}

let main = function () {
    console.log('小胖友来玩呀 1.玩,投币一元 2.不玩');
    let opt = readline.question() - 0;
    while (true) {
        switch (opt) {
            case 1://玩
                let computer_point = createRandom(10, 21);//电脑点数
                let player_point = 0;//玩家点数
                let state = true;//控制抽卡循环
                while (state) {
                    console.log('1.抽 2.不抽');
                    let choose = readline.question() - 0;
                    switch (choose) {
                        case 1://抽
                            let point = createRandom(1, 10);
                            player_point += point;
                            if (player_point > 21) {
                                judge(player_point, -1)
                                state = false;
                            }
                            console.log(player_point, computer_point);
                            break;
                        case 2://不抽
                            judge(player_point, computer_point);
                            state = false;
                            break;
                    }
                }
                console.log('按任意键再来一局，n:不玩了，来不起了');
                let agin = readline.question();
                if (agin == 'n' || agin == 'N') {
                    console.log('欢迎下次光～～临');
                    return;//打断函数
                }


                break;
            case 2://不玩
                console.log(886);
                break;
        }
    }


}


main()


//随机数函数
function createRandom(min = 0, max = 0) {
    // 当min和max传反时，交换
    if (min > max) {
        [min, max] = [max, min]
    }
    let random = parseInt(Math.random() * (max - min + 1) + min)
    return random;
}